package com.xidian.GMS.controller;

import java.text.ParseException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.EnterpriseInformation;
import com.xidian.GMS.mapper.EnterpriseInformationMapper;
import com.xidian.GMS.service.EnterpriseInfoService;

@Controller

public class EnterpriseInfoController {
	@Autowired 
	  private EnterpriseInfoService enterpriseInfoService;
	@RequestMapping(value="/EnterpriseInfoEdit",method=RequestMethod.GET)
	public String update0(int enterpriseid,Model model){
		model.addAttribute("enterpriseid",enterpriseid);
		return "EnterpriseInfoEdit";
	}
	
	@RequestMapping(value="/EnterpriseInfoEdit",method=RequestMethod.POST)
	public String update(EnterpriseInformation enterpriseinfo){
		enterpriseInfoService.update(enterpriseinfo);
		return "EnterpriseInfoIndex";
	}
	
	@RequestMapping(value="/EnterpriseInfoInsert",method=RequestMethod.POST)
	public String Insert(EnterpriseInformation enterpriseinfo){
		System.out.println(enterpriseinfo);
		try{
			enterpriseInfoService.insert(enterpriseinfo);
			return "EnterpriseInfoIndex";
		}catch(Exception e){
			return "EnterpriseInfoInsert";
		}
	}
	@RequestMapping(value="/EnterpriseInfoInsert",method=RequestMethod.GET)
	public String insert(){
		return "EnterpriseInfoIndex";
	}
	
    @RequestMapping(value="/EnterpriseInfo",method=RequestMethod.GET)
    public String Insert2(){
    	System.out.println("aaaaa");
    	return "EnterpriseInfo";
    }
    
    @RequestMapping(value="/EnterpriseInfoDelete",method=RequestMethod.GET)
    public String delete(int enterpriseid){
    	try{
    		System.out.println("123");
    		enterpriseInfoService.delete(enterpriseid);
    		System.out.println("312");
    		return "forward:/fun9-enterpriseinformation.html";
    	}catch(Exception e){
    		return "EnterpriseInfoInsert";
    	}
    }
    
    @RequestMapping(value="/EnterpriseInfoIndex",method=RequestMethod.POST)
    public String IndexPost(){
    	return "EnterpriseInfoIndex";
    }
    
//    @RequestMapping(value="/EnterpriseInfoIndex",method=RequestMethod.GET)
//    public String IndexGET(){
//    	return "EnterpriseInfoIndex";
//    }
    @RequestMapping(value="/EnterpriseInfoIndex",method= RequestMethod.GET)
    @ResponseBody
    public Page InsertGet(@RequestParam(name="cur", defaultValue="1") int cur, Model model){
    	Page page = enterpriseInfoService.getEnterpriseInformation(cur);
    	System.out.println(page);
     	model.addAttribute("page", page);
    	
    	
    		return page;
    		// TODO: handle exception
    	
    	
    }
}

